package greedy;

public class LemonadeChange860 {
    public boolean lemonadeChange(int[] bills) {
        int[] rest = new int[3];
        for (int i = 0; i < rest.length; i++) {
            rest[i] = 0;
        }
        for (int i = 0; i < bills.length; i++) {
            int bill = bills[i];
            if(bill == 5){
                rest[0]++;
                continue;
            }
            if(bill == 10){
                if(rest[0]!=0){
                    rest[1]++;
                    rest[0]--;
                    continue;
                }
            }

            if(bill==20){
                if(rest[1]!=0&&rest[0]!=0){
                    rest[1]--;
                    rest[0]--;
                    rest[2]++;
                    continue;
                }
                if(rest[0]>=3){
                    rest[0] = rest[0]-3;
                    rest[2]++;
                    continue;
                }

            }
            return false;
        }
        return true;
    }
}
